/**
 * @(#) RobotController.java
 */

package pcsr.hwVirtualization;

import java.util.concurrent.atomic.AtomicBoolean;

class RobotController extends Thread
{
	int mySleep;
	public AtomicBoolean run = new AtomicBoolean();
	private Robot controlledRobot;
	private IRobotController robotControllerDriver;
		
	public RobotController(Robot robot, IRobotController robotDriver)
	{
		controlledRobot = robot;
		robotControllerDriver = robotDriver;
	}
	
	public void run( ) {
		
		while (run.get()) {
			try {
				sleep(mySleep);
			} catch (InterruptedException e) {
			}
			
			for(Sensor s : controlledRobot.GetAllSensors())
			{
				// TODO Inform Robot about the new Status
				Sensor newSensorStatus = robotControllerDriver.GetSensorStatus(s);
				controlledRobot.SensorChanged(newSensorStatus);
			}
			
			for(Actuator a : controlledRobot.GetAllActuators())
			{
				// TODO Inform Robot about the new status
				Actuator newActuatorStatus = robotControllerDriver.GetActuatorStatus(a);
				controlledRobot.ActuatorChanged(newActuatorStatus);
			}
		}
	}
}
